package com.zxs.domain.handel.subject;

import com.zxs.common.enums.SubjectInfoTypeEnum;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 题目类型工厂
 *
 * @author zxs
 * @date 2025/11/16 上午4:11
 */
@Component
public class SubjectTypeHandelFactory implements InitializingBean {

    @Autowired
    private List<SubjectTypeHandel> subjectTypeHandelList;

    private Map<SubjectInfoTypeEnum,SubjectTypeHandel> subjectTypeHandelMap = new HashMap<>();

    public SubjectTypeHandel getHandel(int subjectType) {
        SubjectInfoTypeEnum resultCodeEnum = SubjectInfoTypeEnum.getResultCodeEnum(subjectType);
        return subjectTypeHandelMap.get(resultCodeEnum);
    }

    /**
     * Bean加载之后做的事情
     * @throws Exception
     */
    @Override
    public void afterPropertiesSet() throws Exception {
        for (SubjectTypeHandel subjectTypeHandel : subjectTypeHandelList) {
            subjectTypeHandelMap.put(subjectTypeHandel.getHandelType(),subjectTypeHandel);
        }
    }
}